package main

import (
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/registry"
	"github.com/micro/go-plugins/registry/consul/v2"
	"micro/proto/rand"
	"micro/rand-service/handler"
	"micro/rand-service/middleware"
)

func main() {
	consulReg := consul.NewRegistry(
		registry.Addrs("127.0.0.1:8500"))

	//流量监控先初始化
	middleware.InitSentinel()

	service := micro.NewService(
		micro.Name("go.micro.test.rand"),
		micro.Registry(consulReg),
		micro.WrapHandler(middleware.LimitingWrapper()))

	service.Init()

	//暴露接口到对应的服务
	_ = rand.RegisterRandHandler(service.Server(), handler.Handler())

	//run起来
	if err := service.Run(); err != nil {
		panic(err)
	}
}
